﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Huirui.Cavan.Presentation.Seedwork;
using Huirui.Cavan.Presentation.ViewModel.StockModule;
using Huirui.Cavan.Application.MainBoundedContext.StockModule;
using Huirui.Cavan.Domain.MainBoundedContext.StockModule;
using Huirui.Cavan.Domain.MainBoundedContext.SearchModule;
using System.Web.Mvc;

namespace Huirui.Cavan.Presentation.Controller.StockModule
{
    public class StockInDetailController : EntityController<StockInOutDetail, long, StockInOutDetailSearch, IStockInDetailViewModel, IStockInOutDetailAppService>, IStockInDetailController
    {
        public override string ControllerName
        {
            get { return ControllerConst.STOCKINDETAIL; }
        }

        public override bool UseDenied
        {
            get { return false; }
        }

        public StockInDetailController()
        {
            this.Model = ModelFactory.CreateModel<IStockInDetailViewModel>();
        }

        [ActionName(ActionConst.LIST)]
        public JsonResult GetStockInDetails(string id)
        {
            StockInDetailJsonViewModel json = new StockInDetailJsonViewModel();
            json.rows = new List<StockInOutDetailJson>();

            long total = 0;
            IList<StockInOutDetail> stockInDetails = this.AppService.GetBySearch(SearchFactory.CreateStockInDetailSearch(id), out total).ToList();
            foreach (StockInOutDetail sid in stockInDetails)
            {
                StockInOutDetailJson sidj = new StockInOutDetailJson();
                sidj.ID = sid.Id;
                sidj.StockID = sid.Stock.Id;
                sidj.StockName = sid.Stock.Name;
                json.rows.Add(sidj);
            }
            json.total = total;

            return Json(json, "application/json");
        }
    }
}
